#include "PianoKeyEvent.h"

const std::vector< std::pair< int, PianoKeyEvent::Event > >& PianoKeyEvent::getContent () const
{
	return _content;
}

bool PianoKeyEvent::addContent (int keyIndex, Event e)
{
	for (size_t i = 0; i < _content.size (); ++i)
		if (_content[i].first == keyIndex) {
			if (e != _content[i].second)
				_content.erase (_content.begin () + i);
			return false;
		}
	_content.push_back (std::make_pair (keyIndex, e));
	return true;
}

PianoKeyEvent PianoKeyEvent::merge (const PianoKeyEvent& e)
{
	PianoKeyEvent newEvent;
	newEvent._content = _content;
	size_t thisCount = _content.size ();
	for (size_t i = 0; i < e._content.size (); ++i) {
		bool isExisted = false;
		for (size_t j = 0; j < thisCount; ++j) {
			if (e._content[i].first == newEvent._content[j].first) {
				if (e._content[i].second != newEvent._content[j].second) {
					newEvent._content.erase (newEvent._content.begin () + j);
					--thisCount;
				}
				isExisted = true;
				break;
			}
		}
		if (!isExisted)
			newEvent._content.push_back (e._content[i]);
	}
	return newEvent;
}